package com.fr.report.painter;

import com.fr.base.FRFont;
import com.fr.base.Style;
import com.fr.base.core.GraphHelper;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

class BiasZone
  implements Cloneable, Serializable
{
  private BiasLine[] biasLine;
  private BiasLineSpan[] biasLineSpan;
  private Rectangle2D paintRectangle;
  private double firstAngle;
  private double secondAngle;
  private String text;
  private Style style;
  private final int typeOne = 1;
  private final int typeTwo = 2;
  private final int otherType = 3;
  private int zoneType = 3;
  private boolean isCenter;
  private boolean isBackSlash;

  BiasZone(Rectangle2D paramRectangle2D, double paramDouble1, double paramDouble2, String paramString, Style paramStyle, int paramInt, boolean paramBoolean1, boolean paramBoolean2)
  {
    this.paintRectangle = paramRectangle2D;
    this.firstAngle = paramDouble1;
    this.secondAngle = paramDouble2;
    this.text = paramString;
    this.style = paramStyle;
    this.isBackSlash = paramBoolean2;
    setZoneType(paramInt);
    setCenter(paramBoolean1);
    initialZone(getZoneType());
  }

  public void initialZone(int paramInt)
  {
    label597: label1386: String str;
    double d15;
    if (this.style == null)
      this.style = Style.DEFAULT_STYLE;
    FRFont localFRFont = this.style.getFRFont();
    FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localFRFont);
    int i = localFontMetrics.getLeading();
    int j = localFontMetrics.getAscent();
    int k = localFontMetrics.getHeight();
    int l = 3;
    double d1 = this.paintRectangle.getWidth();
    double d2 = this.paintRectangle.getHeight();
    ArrayList localArrayList1 = new ArrayList();
    StringTokenizer localStringTokenizer = new StringTokenizer(this.text, "\n", false);
    BiasLine.getStringInLine().clear();
    ArrayList localArrayList2 = new ArrayList();
    localArrayList2.clear();
    while (localStringTokenizer.hasMoreTokens())
      localArrayList2.add(localStringTokenizer.nextToken());
    double d3 = 0.0D;
    double d4 = 0.0D;
    for (int i1 = 0; i1 < localArrayList2.size(); ++i1)
    {
      d3 += k;
      double d5 = localFontMetrics.stringWidth((String)localArrayList2.get(i1));
      if (d4 < d5)
        d4 = d5;
    }
    i1 = k;
    ArrayList localArrayList3 = new ArrayList();
    if (this.isBackSlash)
    {
      switch (paramInt)
      {
      case 1:
        i1 = k;
        while (i1 < d2)
        {
          double d6 = (d2 - i1) / Math.tan(this.secondAngle / 180.0D * 3.141592653589793D);
          if (l < d6)
            localArrayList3.add(new BiasLineSpan(new Point2D.Double(1.0D, i1 - k - d2), new Point2D.Double(d6 - 1.0D, i1 - k - d2)));
          i1 += k;
        }
        this.biasLineSpan = new BiasLineSpan[localArrayList3.size()];
        int i2 = 0;
        while (true)
        {
          if (i2 >= this.biasLineSpan.length)
            break label597;
          this.biasLineSpan[i2] = ((BiasLineSpan)localArrayList3.get(i2));
          ++i2;
        }
      case 2:
        localArrayList3.clear();
        i1 = k;
        while (i1 < d1 * Math.tan(this.firstAngle / 180.0D * 3.141592653589793D))
        {
          double d7 = i1 / Math.tan(this.firstAngle / 180.0D * 3.141592653589793D);
          if (l < d7)
            localArrayList3.add(0, new BiasLineSpan(new Point2D.Double(d7 + 1.0D, -i1), new Point2D.Double(d1 - 1.0D, -i1)));
          i1 += k;
        }
        this.biasLineSpan = new BiasLineSpan[localArrayList3.size()];
        int i3 = 0;
        while (true)
        {
          if (i3 >= this.biasLineSpan.length)
            break label597;
          this.biasLineSpan[i3] = ((BiasLineSpan)localArrayList3.get(i3));
          ++i3;
        }
      case 3:
        localArrayList3.clear();
        this.biasLineSpan = null;
      }
    }
    else
    {
      double d11;
      double d13;
      double d14;
      switch (paramInt)
      {
      case 1:
        double d8;
        localArrayList3.clear();
        if (this.isCenter)
        {
          d8 = Math.tan(this.secondAngle / 180.0D / 2.0D * 3.141592653589793D);
          d11 = this.paintRectangle.getWidth() / (d8 + 1.0D);
          d13 = 0.0D;
          d14 = d11 - d4 / 2.0D;
          d15 = (d11 - d4 / 2.0D) * Math.tan(this.secondAngle / 180.0D * 3.141592653589793D);
          if (d15 > d3)
            d13 = (d15 - d3) / 2.0D;
          i1 = k;
          while (true)
          {
            if (i1 > d15)
              break label922;
            localArrayList3.add(new BiasLineSpan(new Point2D.Double(d14, d13 + i1 - k), new Point2D.Double(d1 - l, d13 + i1 - k)));
            i1 += k;
          }
        }
        i1 = k;
        while (i1 < d2)
        {
          d8 = i1 / Math.tan(this.secondAngle / 180.0D * 3.141592653589793D);
          if (d8 + l < d1)
            localArrayList3.add(new BiasLineSpan(new Point2D.Double(d8, i1 - k), new Point2D.Double(d1 - l, i1 - k)));
          i1 += k;
        }
        this.biasLineSpan = new BiasLineSpan[localArrayList3.size()];
        int i4 = 0;
        while (true)
        {
          if (i4 >= this.biasLineSpan.length)
            break label1386;
          this.biasLineSpan[i4] = ((BiasLineSpan)localArrayList3.get(i4));
          ++i4;
        }
      case 2:
        double d9;
        localArrayList3.clear();
        if (this.isCenter)
        {
          d9 = Math.tan((45.0D + this.firstAngle / 2.0D) / 180.0D * 3.141592653589793D);
          d11 = this.paintRectangle.getHeight() / (d9 + 1.0D);
          d13 = 0.0D;
          d14 = d11 + d4 / 2.0D;
          d15 = (this.paintRectangle.getHeight() / Math.tan(this.firstAngle / 180.0D * 3.141592653589793D) - d11 + d4 / 2.0D) * Math.tan(this.firstAngle / 180.0D * 3.141592653589793D);
          d13 = this.paintRectangle.getHeight() - d15;
          if (d15 > d3)
            d13 = (2.0D * this.paintRectangle.getHeight() - d15 - d3) / 2.0D;
          i1 = k;
          do
          {
            if (i1 > d15)
              break label1329;
            localArrayList3.add(new BiasLineSpan(new Point2D.Double(5.0D, d13 + i1 - k), new Point2D.Double(d14, d13 + i1 - k)));
            i1 += k;
          }
          while (i1 <= d3 + 3.0D);
        }
        else
        {
          i1 = k;
          while (i1 < d2)
          {
            d9 = (d2 - i1) / Math.tan(this.firstAngle / 180.0D * 3.141592653589793D);
            if (l < d9)
              localArrayList3.add(0, new BiasLineSpan(new Point2D.Double(5.0D, d2 - i1), new Point2D.Double(d9 - 1.0D, d2 - i1)));
            i1 += k;
          }
        }
        this.biasLineSpan = new BiasLineSpan[localArrayList3.size()];
        d10 = 0;
        while (true)
        {
          if (d10 >= this.biasLineSpan.length)
            break label1386;
          this.biasLineSpan[d10] = ((BiasLineSpan)localArrayList3.get(d10));
          ++d10;
        }
      case 3:
        label922: label1329: this.biasLineSpan = null;
      }
    }
    super.getClass();
    if (getZoneType() == 1)
    {
      d10 = 0;
      while (true)
      {
        if (d10 >= localArrayList2.size())
          break label1830;
        str = (String)localArrayList2.get(d10);
        BiasLine localBiasLine1 = new BiasLine(str, this.style);
        localArrayList1.add(localBiasLine1);
        localBiasLine1.initial(this.biasLineSpan);
        ++d10;
      }
    }
    super.getClass();
    if (getZoneType() == 2)
    {
      d10 = 0;
      int i5 = -1;
      for (int i6 = this.biasLineSpan.length - 1; i6 >= 0; --i6)
      {
        d12 = 0.0D;
        int i8 = i6;
        int i9 = 0;
        int i10 = 1;
        while (i9 < localArrayList2.size())
        {
          i10 = 1;
          str = (String)localArrayList2.get(i9);
          d15 = localFontMetrics.stringWidth(str);
          for (int i11 = i8; i11 < this.biasLineSpan.length; ++i11)
          {
            d12 += this.biasLineSpan[i11].getLineWidth();
            if (d12 > d15)
            {
              i8 = i11 + 1;
              d12 = 0.0D;
              i10 = 0;
              if (i9 != localArrayList2.size() - 1)
                break;
              i5 = i6;
              break;
            }
          }
          if (i10 != 0)
            break;
          ++i9;
        }
        if (i5 != -1)
          break;
      }
      if ((i5 != -1) && (i5 > 0))
        d10 = i5 - 1;
      BiasLineSpan[] arrayOfBiasLineSpan = new BiasLineSpan[this.biasLineSpan.length - d10];
      for (double d12 = d10; d12 < this.biasLineSpan.length; ++d12)
        arrayOfBiasLineSpan[(d12 - d10)] = new BiasLineSpan(this.biasLineSpan[d12].getStartPoint(), this.biasLineSpan[d12].getEndPoint());
      this.biasLineSpan = arrayOfBiasLineSpan;
      int i7 = 0;
      while (true)
      {
        if (i7 >= localArrayList2.size())
          break label1830;
        str = (String)localArrayList2.get(i7);
        BiasLine localBiasLine2 = new BiasLine(str, this.style);
        localArrayList1.add(localBiasLine2);
        localBiasLine2.initial(this.biasLineSpan);
        ++i7;
      }
    }
    super.getClass();
    if (getZoneType() == 3);
    label1830: this.biasLine = new BiasLine[localArrayList1.size()];
    for (double d10 = 0; d10 < localArrayList1.size(); ++d10)
      this.biasLine[d10] = ((BiasLine)localArrayList1.get(d10));
  }

  public void paintZone(Graphics2D paramGraphics2D)
  {
    int i;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics2D.create();
    switch (getZoneType())
    {
    case 1:
      i = 0;
      while (true)
      {
        if (i >= this.biasLine.length)
          return;
        this.biasLine[i].paintBiasLine(localGraphics2D, this.isCenter);
        ++i;
      }
    case 2:
      i = 0;
      while (true)
      {
        if (i >= this.biasLine.length)
          return;
        this.biasLine[i].paintBiasLine(localGraphics2D, this.isCenter);
        ++i;
      }
    case 3:
      if (this.style == null)
        this.style = Style.DEFAULT_STYLE;
      FRFont localFRFont = this.style.getFRFont();
      FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localFRFont);
      double d3 = localFontMetrics.getHeight();
      double d4 = localFontMetrics.getAscent();
      if (this.isBackSlash)
      {
        d5 = (this.firstAngle + this.secondAngle) / 2.0D;
        d1 = d3 / 2.0D / Math.tan((this.firstAngle - d5) / 180.0D * 3.141592653589793D);
        d2 = -d3 / 2.0D;
        localGraphics2D.rotate(-3.141592653589793D * d5 / 180.0D);
        localGraphics2D.drawString(this.text, (float)d1, (float)(d2 + d4));
        return;
      }
      double d5 = (this.firstAngle + this.secondAngle) / 2.0D;
      double d1 = d3 / 2.0D / Math.tan((d5 - this.firstAngle) / 180.0D * 3.141592653589793D);
      double d2 = -d3 / 2.0D;
      localGraphics2D.rotate(3.141592653589793D * d5 / 180.0D);
      localGraphics2D.drawString(this.text, (float)d1, (float)(d2 + d4));
    }
  }

  public BiasLine[] getBiasLine()
  {
    return this.biasLine;
  }

  public void setBiasLine(BiasLine[] paramArrayOfBiasLine)
  {
    this.biasLine = paramArrayOfBiasLine;
  }

  public BiasLineSpan[] getBiasLineSpan()
  {
    return this.biasLineSpan;
  }

  public void setBiasLineSpan(BiasLineSpan[] paramArrayOfBiasLineSpan)
  {
    this.biasLineSpan = paramArrayOfBiasLineSpan;
  }

  public int getZoneType()
  {
    return this.zoneType;
  }

  public void setZoneType(int paramInt)
  {
    this.zoneType = paramInt;
  }

  public boolean isCenter()
  {
    return this.isCenter;
  }

  public void setCenter(boolean paramBoolean)
  {
    this.isCenter = paramBoolean;
  }
}